package com.itlong.cloud.app;

import com.itlong.cloud.equip.app.IAppDevicePassRecordServiceClient;
import com.itlong.cloud.utils.date.DateUtil;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

/**
 * <desc>
 *      App用户通行记录任务调度类
 * </desc>
 *
 * @createDate 2017/11/10
 */
@EnableScheduling // 启用定时任务
@RestController
public class AppDevicePassRecordTimeTask {
    private static Logger LOG = LoggerFactory.getLogger(AppDevicePassRecordTimeTask.class);

    @Autowired
    IAppDevicePassRecordServiceClient iAppDevicePassRecordServiceClient;

    /**
     * <desc>
     *      同步通行记录至具体设备通行记录表
     * </desc>
     *
     * @author Jiaqi.X
     * @creatDate 2017/11/10
     */
    @Scheduled(cron = "0 0/5 * * * ?") // 每5分钟同步一次
    public void timeTaskSychro() {
        try {
            iAppDevicePassRecordServiceClient.timeTaskSychro();
//            LOG.info("【定时任务】同步通行记录至具体设备通行记录表执行成功，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));
        }catch (Exception e){
            LOG.error("【定时任务】同步通行记录至具体设备通行记录表执行失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"),e);
        }
    }

    /**
     * <desc>
     *      以用户为基准删除通行时间大于3个月的记录
     * </desc>
     *
     * @author Jiaqi.X
     * @creatDate 2017/11/13
     */
    @Scheduled(cron = "0 6 0 * * ?") // 每天凌晨执行
    public void timeTaskClear() {
        try {
            iAppDevicePassRecordServiceClient.timeTaskDeleteRecord();
//            LOG.info("【定时任务】以用户为基准删除通行时间大于3个月的记录执行成功，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));
        }catch (Exception e){
            LOG.error("【定时任务】以用户为基准删除通行时间大于3个月的记录执行失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"),e);
        }
    }


}
